
package com.scs.application.modules.msg.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;

import com.scs.application.core.model.CommonResult;
import com.scs.application.core.model.PageResult;
import com.scs.application.core.mvc.controller.BaseController;
import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.modules.ext.entity.CertHosup;
import com.scs.application.modules.ext.service.CertHosupService;
import com.scs.application.modules.msg.entity.PushedRecord;
import com.scs.application.modules.msg.request.PushedRecordQueryRequest;
import com.scs.application.modules.msg.service.PushedRecordService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
* 已推送记录 controller
*
*/
@AllArgsConstructor
@RestController
@RequestMapping("/msg/pushed_records")
public class PushedRecordController  extends CrudController<PushedRecord, String, PushedRecordService> {

    private final PushedRecordService pushedRecordService;

    @PostMapping
    public CommonResult add(@RequestBody @Valid PushedRecord entity) {
        boolean bSave = pushedRecordService.saveCascadeById(entity);
        return bSave ? CommonResult.ok("新增成功", entity) : CommonResult.error("新增失败");
    }

    @PutMapping
    public CommonResult update(@RequestBody @Valid PushedRecord entity) {
        boolean bUpdate = pushedRecordService.updateCascadeById(entity);
        return bUpdate ? CommonResult.ok("保存成功", entity) : CommonResult.error("保存失败");
    }

    @GetMapping("/page")
    public PageResult page(PushedRecordQueryRequest request) {
        IPage page = pushedRecordService.page(request);
        return PageResult.ok("查询成功", page.getRecords(), page.getTotal());
    }

    @GetMapping("/list")
    public CommonResult list(PushedRecordQueryRequest request) {
        List<PushedRecord> list = pushedRecordService.list(request);
        return CommonResult.ok("查询成功", list);
    }


    @DeleteMapping("/{id}")
    public CommonResult deleteById(@PathVariable("id") String id) {
        boolean bRemove = pushedRecordService.removeCascadeById(id);
        return bRemove ? CommonResult.ok("删除成功") : CommonResult.error("删除失败");
    }

}
